home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9972 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: goto
  5. Date: Thu, 14 Mar 96 17:48:36 GMT
  6. Organization: none
  7. Message-ID: <826825716snz@genesis.demon.co.uk>
  8. References: <Pine.OSF.3.91.960313102715.10701D-100000@io.UWinnipeg.ca> <wpmills.826820253@wpmills>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <wpmills.826820253@wpmills> wpmills@midusa.net "W. Paul Mills" writes:
  15.  
  16. >Bill Simpson <wsimpson@uwinnipeg.ca> writes:
  17. >
  18. >>There was a goto thread lately, and my problem is to state this algorithm 
  19. >>cleanly without gotos (which I think is easy, but my attempts have been 
  20. >>failures).
  21. >
  22. >>0. x=0;
  23. >>1. x+=erand(maxmean);
  24. >>2. if (urand2()>rate(x)/maxrate)
  25. >>       goto step 1
  26. >>3. if (x<=XMAX)
  27. >>       {
  28. >>       setdot(x,y,z);
  29. >>       goto step 1
  30. >>       }
  31. >>explanation:
  32. >>erand(mean) returns exponential double random number with given mean
  33. >>urand2() returns uniform double random number between 0 & 1
  34. >>rate(). well the rate of the Poisson process varies with x
  35.  
  36.     for (x = 0; ; ) {
  37.         x += erand(maxmean);
  38.  
  39.         if (urand2() <= rate(x)/maxrate) {
  40.             if (x > XMAX)
  41.                 break;
  42.  
  43.             setdot(x, y, z);
  44.         }
  45.     }
  46.  
  47. I have reversed the sense of the comparisons here, you will have to decide
  48. of that has made it less clear.
  49.  
  50. >x = 0
  51.  
  52.       ;
  53.  
  54. >do {
  55. >        x += erand(maxmean);
  56. >        if (urand2() > rate(x) / maxrate) continue;
  57. >        setdot(x, y, z);
  58. >   } while ( x < XMAX);
  59.                 <=
  60.  
  61. This doesn't do what was asked (for example the specification will only
  62. call setdot() if x<=XMAX whereas yours can call it with a larger value).
  63.  
  64. -- 
  65. -----------------------------------------
  66. Lawrence Kirby | fred@genesis.demon.co.uk
  67. Wilts, England | 70734.126@compuserve.com
  68. -----------------------------------------
  69.